package lanQiaoBei.搜索与图论.dfs;

import java.io.*;

/*
 *给定一个整数n,将数字1-n排成一排将会有很多种排列方式
 * 请你将所有排列方式列出
 * */
public class P1 {
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    final static int N = 10010;
    static int n;
    static int[] path = new int[N];
    static boolean[] isExist = new boolean[N];

    static void dfs(int d) {
        if (d == n) {
               for(int i=0;i<n;i++){
                   System.out.print(path[i]);
               }
               System.out.println();
            return;
        }
        for (int i = 1; i <= n; i++) {
            if (!isExist[i]) {
                isExist[i] = true;
                path[d] = i;
                dfs(d + 1);
                isExist[i] = false;
            }
        }
    }

    public static void main(String[] args) throws Exception {
        n = Integer.parseInt(br.readLine());
        dfs(0);
    }
}
